package com.hadoop.ex;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class DelayCountMapperWithDateKey extends
		Mapper<LongWritable, Text, DateKey, IntWritable> {

	private final static IntWritable outputValue = new IntWritable(1);

	private DateKey outputKey = new DateKey();

	public void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {

		if (key.get() > 0) {
			String[] colums = value.toString().split(",");
			if (colums != null && colums.length > 0) {
				try {
					outputKey.setYear("D," + colums[0]);
					outputKey.setMonth(new Integer(colums[1]));
					context.write(outputKey, outputValue);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
